package com.cy.pj.sys.web.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.service.SysLogService;
import com.cy.pj.sys.web.pojo.JsonResult;
import com.github.pagehelper.ISelect;
import org.apache.ibatis.annotations.Lang;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



//restful(赖s) 风格url(一种编码风格)
//@GetMapping 所有-->/log/
//@GetMapping 某个-->/log/{id}
//@DeleteMapping 某些-->/log/{id}
//请求路径相同也不会报错,还可以根据请求的方式进行请求

@RestController
@RequestMapping("/log/")
public class SysLogController {
    @Autowired
     private SysLogService sysLogService;

//    @GetMapping("doFindLogs")
@GetMapping
public JsonResult doFindLogs(SysLog sysLog){
//        return new JsonResult(PageUtil.startPage().doSelectPageInfo(()->
//                sysLogService.findLogs(sysLog)
//        ));//lambda (jdk8 中特性)
    return new JsonResult(PageUtil.startPage().doSelectPageInfo(
            new ISelect() {
                @Override
                public void doSelect() {
                    sysLogService.findLogs(sysLog);
                }
            }));
}
//    @GetMapping("findById/{id}")
    @GetMapping("{id}")
    public JsonResult findById(@PathVariable Long id){
        return new JsonResult(sysLogService.findById(id));
    }
//    @DeleteMapping("doDelete/{ids}")
    @DeleteMapping("{id}")
    public JsonResult doDelete(@PathVariable Long... id){
        sysLogService.deleteLogs(id);
        return new JsonResult("delete ok");
    }


}
